from .servo import Servo
from .config import config
import time

class handServo():
    r1,r2,r3,r4,r5=[],[],[],[],[]
    l1,l2,l3,l4,l5=[],[],[],[],[]
    def __init__(self):
        self.hand={
            "humb":Servo(config["humb"]),
            "index":Servo(config["index"]),
            "middle":Servo(config["middle"]),
            "finger":Servo(config["finger"]),
            "pinky":Servo(config["pinky"]),
        }
        self.start_time = time.time()
        self.current_nums = 0
        self.max_nums = 10
        pass
    def dirver(self,handlist):
        lefthand=handlist["left"]
        righthand=handlist["right"]
        #if round(time.time()-self.start_time,0)<0.5:#以时间
        if self.max_nums-self.current_nums>0:#以数量
            if righthand:
                r1,r2,r3,r4,r5=zip(righthand)
                self.hand["humb"].append(r1)
                self.hand["index"].append(r2)
                self.hand["middle"].append(r3)
                self.hand["finger"].append(r4)
                self.hand["pinky"].append(r5)
                self.current_nums = self.current_nums+1
        else:
            if righthand:
                self.hand["humb"].start()
                self.hand["index"].start()
                self.hand["middle"].start()
                self.hand["finger"].start()
                self.hand["pinky"].start()
                self.start_time = time.time()
                self.current_nums = 0
                time.sleep(0.01)